package 递归.两两交换链表中的节点;

public class Main {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val,ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        ListNode tmp = head.next.next;
        ListNode newHead = head.next;
        newHead.next=head;
        head.next = swapPairs(tmp);
        return newHead;
    }
}
